﻿Imports System.Drawing
Imports System.Windows.Forms

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class DetailListBox
    Inherits System.Windows.Forms.ListBox

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.ResizeRedraw = True
        Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable

    End Sub

#Region "Designer Generated Code"
    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private WithEvents components As System.Windows.Forms.ListBox

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        '
        'components
        '
        Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawVariable
        Me.components.Location = New System.Drawing.Point(0, 0)
        Me.components.Name = "DetailListBox"
        Me.components.Size = New System.Drawing.Size(100, 23)
        Me.components.TabIndex = 0
        '
        'VerticalContainerLabel
        '
        Me.Name = "DetailListBox"
        Me.ResumeLayout(False)
    End Sub
#End Region

#Region "Exposed Properties"
    Private iTextheigtCompensation As Integer = 30
    'Public Property TextheigtCompensation As Integer
    '    Get
    '        Return Me.iTextheigtCompensation
    '    End Get
    '    Set(value As Integer)
    '        Me.iTextheigtCompensation = value
    '    End Set
    'End Property
    Private iGraphicsLineBreak As Integer = 1
    'Public Property GraphicsLineBreak As Integer
    '    Get
    '        Return Me.iGraphicsLineBreak
    '    End Get
    '    Set(value As Integer)
    '        Me.iGraphicsLineBreak = value
    '    End Set
    'End Property
    Private iItemBackColorNormal As Color = SystemColors.InactiveBorder
    'Public Property ItemBackColorNormal As Color
    '    Get
    '        Return Me.iItemBackColorNormal
    '    End Get
    '    Set(value As Color)
    '        Me.iItemBackColorNormal = value
    '    End Set
    'End Property
    Private iItemBackColorSelected As Color = SystemColors.ActiveCaption
    'Public Property ItemBackColorSelected As Color
    '    Get
    '        Return Me.iItemBackColorSelected
    '    End Get
    '    Set(value As Color)
    '        Me.iItemBackColorSelected = value
    '    End Set
    'End Property
    Private iItemForeColorNormal As Color = SystemColors.ControlText
    'Public Property ItemForeColorNormal As Color
    '    Get
    '        Return Me.iItemForeColorNormal
    '    End Get
    '    Set(value As Color)
    '        Me.iItemForeColorNormal = value
    '    End Set
    'End Property
    Private iItemForeColorSelected As Color = SystemColors.HighlightText
    'Public Property ItemForeColorSelected As Color
    '    Get
    '        Return Me.iItemForeColorSelected
    '    End Get
    '    Set(value As Color)
    '        Me.iItemForeColorSelected = value
    '    End Set
    'End Property
    Private iImagePositioning As ImagePositioningsEnum = ImagePositioningsEnum.Left
    'Public Property ImagePositioning As ImagePositioningsEnum
    '    Get
    '        Return Me.iImagePositioning
    '    End Get
    '    Set(value As ImagePositioningsEnum)
    '        Me.iImagePositioning = value
    '    End Set
    'End Property
    Private iImageAlignment As ContentAlignment = ContentAlignment.MiddleCenter
    'Public Property ImageAlignment As ContentAlignment
    '    Get
    '        Return Me.iImageAlignment
    '    End Get
    '    Set(value As ContentAlignment)
    '        Me.iImageAlignment = value
    '    End Set
    'End Property
    Private iHeaderAlignment As ContentAlignment = ContentAlignment.MiddleLeft
    'Public Property HeaderAlignment As ContentAlignment
    '    Get
    '        Return Me.iHeaderAlignment
    '    End Get
    '    Set(value As ContentAlignment)
    '        Me.iHeaderAlignment = value
    '    End Set
    'End Property
    Private iHeaderFont As Font = New Font(Me.Font, FontStyle.Bold)
    'Public Property HeaderFont As Font
    '    Get
    '        Return Me.iHeaderFont
    '    End Get
    '    Set(value As Font)
    '        Me.iHeaderFont = value
    '    End Set
    'End Property
    Private iDetailsAlignment As ContentAlignment = ContentAlignment.MiddleLeft
    'Public Property DetailsAlignment As ContentAlignment
    '    Get
    '        Return Me.iDetailsAlignment
    '    End Get
    '    Set(value As ContentAlignment)
    '        Me.iDetailsAlignment = value
    '    End Set
    'End Property
    Private iDetailsFont As Font = Me.Font
    'Public Property DetailsFont As Font
    '    Get
    '        Return Me.iDetailsFont
    '    End Get
    '    Set(value As Font)
    '        Me.iDetailsFont = value
    '    End Set
    'End Property
    Private iFooterAlignment As ContentAlignment = ContentAlignment.BottomRight
    'Public Property FooterAlignment As ContentAlignment
    '    Get
    '        Return Me.iFooterAlignment
    '    End Get
    '    Set(value As ContentAlignment)
    '        Me.iFooterAlignment = value
    '    End Set
    'End Property
    Private iFooterFont As Font = New Font(Me.Font, FontStyle.Bold)
    'Public Property FooterFont As Font
    '    Get
    '        Return Me.iFooterFont
    '    End Get
    '    Set(value As Font)
    '        Me.iFooterFont = value
    '    End Set
    'End Property
#End Region

#Region "Custom List Drawing"

    Protected Overrides Sub OnDrawItem(e As System.Windows.Forms.DrawItemEventArgs)
        MyBase.OnDrawItem(e)

        If Me.Items.Count > 0 Then
            If e.Index <> -1 Then

                'stop layout to avoid flicker
                Me.SuspendLayout()

                Dim gh As New GraphicsHelper

                'Get the actual bounds ie - border
                Dim itemBounds As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height)

                'Draw background
                Dim textBrush As Brush = Nothing
                If ((e.State And DrawItemState.Selected) = DrawItemState.Selected) Then
                    e.Graphics.FillRectangle(New SolidBrush(Me.iItemBackColorSelected), e.Bounds)
                    textBrush = New SolidBrush(Me.iItemForeColorSelected)
                Else
                    e.Graphics.FillRectangle(New SolidBrush(Me.iItemBackColorNormal), e.Bounds)
                    textBrush = New SolidBrush(Me.iItemForeColorNormal)
                End If

                If TypeOf Me.Items(e.Index) Is DetailListBoxItem Then

                    'Get the item
                    Dim item As DetailListBoxItem = Me.Items(e.Index)

                    'if image exists first get image rectangle
                    Dim textRectangle As Rectangle = Nothing
                    If item.IconImage IsNot Nothing Then
                        'Draw image
                        Dim imgrectangle As Rectangle = gh.GetImageRectangleProportionalAligned(item.IconImage, itemBounds, ImagePositioningsEnum.Left)
                        'Dim imgrectangle As Rectangle = gh.GetImageRectangleProportionalCentered(item.IconImage, itemBounds)
                        e.Graphics.DrawImage(item.IconImage, imgrectangle)
                        textRectangle = gh.GetTextRectangleOpositeToImageRectangle(itemBounds, imgrectangle, Me.iImagePositioning)
                    Else
                        textRectangle = itemBounds
                    End If

                    'Draw text items
                    If (item.Details <> "") _
                        AndAlso (item.Footer <> "") Then        'Header, Details, Footer all available

                        'Header
                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                textRectangle.Width, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim headerRectangle As New Rectangle(textRectangle.X, _
                                                             textRectangle.Y, _
                                                             headerSize.Width, _
                                                             headerSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, headerRectangle)
                        e.Graphics.DrawString(item.Header, _
                                              Me.iHeaderFont, _
                                              textBrush, _
                                              headerRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        'Details
                        Dim detailsSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Details, _
                                                                Me.iDetailsFont, _
                                                                textRectangle.Width, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))
                        Dim detailsRectangle As New Rectangle(textRectangle.X, _
                                                              textRectangle.Y + headerSize.Height + Me.iGraphicsLineBreak, _
                                                              detailsSize.Width, _
                                                              detailsSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, detailsRectangle)
                        e.Graphics.DrawString(item.Details, _
                                              Me.iDetailsFont, _
                                              textBrush, _
                                              detailsRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))
                        'Footer
                        Dim footerSize As Size = gh.GetTextSize(Me.Handle, _
                                        item.Footer, _
                                        Me.iFooterFont, _
                                        textRectangle.Width, _
                                        gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))
                        Dim footerRectangle As New Rectangle(textRectangle.X, _
                                                              textRectangle.Bottom - footerSize.Height - Me.iGraphicsLineBreak, _
                                                              footerSize.Width, _
                                                              footerSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, footerRectangle)
                        e.Graphics.DrawString(item.Footer, _
                                              Me.iFooterFont, _
                                              textBrush, _
                                              footerRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))

                    ElseIf (item.Details <> "") _
                        AndAlso (item.Footer = "") Then     'Header, Details available

                        'Header
                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                textRectangle.Width, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim headerRectangle As New Rectangle(textRectangle.X, _
                                                             textRectangle.Y, _
                                                             headerSize.Width, _
                                                             headerSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, headerRectangle)
                        e.Graphics.DrawString(item.Header, _
                                              Me.iHeaderFont, _
                                              textBrush, _
                                              headerRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        'Details
                        Dim detailsSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Details, _
                                                                Me.iDetailsFont, _
                                                                textRectangle.Width, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))
                        Dim detailsRectangle As New Rectangle(textRectangle.X, _
                                                              textRectangle.Y + headerSize.Height + Me.iGraphicsLineBreak, _
                                                              detailsSize.Width, _
                                                              detailsSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, detailsRectangle)
                        e.Graphics.DrawString(item.Details, _
                                              Me.iDetailsFont, _
                                              textBrush, _
                                              detailsRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))

                    ElseIf (item.Details = "") _
                        AndAlso (item.Footer <> "") Then     'Header,Footer available

                        'Header
                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                textRectangle.Width, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim headerRectangle As New Rectangle(textRectangle.X, _
                                                             textRectangle.Y, _
                                                             headerSize.Width, _
                                                             headerSize.Height)
                        e.Graphics.DrawString(item.Header, _
                                              Me.iHeaderFont, _
                                              textBrush, _
                                              headerRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))

                        'Footer
                        Dim footerSize As Size = gh.GetTextSize(Me.Handle, _
                                        item.Footer, _
                                        Me.iFooterFont, _
                                        textRectangle.Width, _
                                        gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))
                        Dim footerRectangle As New Rectangle(textRectangle.X, _
                                                              textRectangle.Bottom - footerSize.Height - Me.iGraphicsLineBreak, _
                                                              footerSize.Width, _
                                                              footerSize.Height)
                        'e.Graphics.DrawRectangle(Pens.Black, headerRectangle)
                        e.Graphics.DrawString(item.Footer, _
                                              Me.iFooterFont, _
                                              textBrush, _
                                              footerRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))
                    Else
                        'e.Graphics.DrawRectangle(Pens.Black, textRectangle)
                        e.Graphics.DrawString(item.Header, _
                                              Me.iHeaderFont, _
                                              textBrush, _
                                              textRectangle, _
                                              gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                    End If
                Else    'Only Header available

                    'Get the item
                    Dim item As Object = Me.Items(e.Index)

                    'Draw text
                    'first create string format
                    Dim sf As StringFormat = gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment)
                    If e.Index = Me.SelectedIndex Then
                        e.Graphics.DrawString(item.ToString, Me.iDetailsFont, New SolidBrush(Me.iItemForeColorSelected), itemBounds, sf)
                    Else
                        e.Graphics.DrawString(item.ToString, Me.iDetailsFont, New SolidBrush(Me.iItemForeColorNormal), itemBounds, sf)
                    End If

                End If


                    'Resume layout which we stop earlier to avoid flicker
                    Me.ResumeLayout()
                End If
            End If
            'If Me.Items.Count > 0 Then
            '    If e.Index <> -1 Then

            '        'Suspend layout
            '        Me.SuspendLayout()

            '        'Drawbackground
            '        If e.Index = Me.SelectedIndex Then
            '            e.Graphics.FillRectangle(New SolidBrush(Me.iSelectionBackgroundColor), e.Bounds)
            '        Else
            '            e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), e.Bounds)
            '        End If

            '        'Get rectangle settings
            '        Dim item As DetailListBoxItem = Me.Items(e.Index)
            '        Dim hSize As SizeF = e.Graphics.MeasureString(item.Header, Me.iHeaderFont, Me.Size.Width)
            '        Dim dSize As SizeF = Nothing
            '        Dim cSize As SizeF = Nothing
            '        If item.Details = "" Then
            '            dSize = New SizeF(0, 0)
            '        Else
            '            dSize = e.Graphics.MeasureString(item.Details, Me.Font, Me.Size.Width)
            '        End If
            '        If item.DueDate = DateTime.MinValue Then
            '            cSize = New SizeF(0, 0)
            '        Else
            '            cSize = e.Graphics.MeasureString(item.DueDate.ToString(Me.iDisplayDateFormat), _
            '                                             Me.iDueDateFont, _
            '                                             Me.Size.Width)
            '        End If

            '        'Draw Header
            '        Dim lineSeperation As Integer = 3
            '        Dim hRect As New Rectangle(e.Bounds.X, _
            '                                   e.Bounds.Y, _
            '                                   e.Bounds.Width, _
            '                                   hSize.Height)
            '        Dim sfHeader As New StringFormat
            '        Select Case Me.iHeaderAlignment
            '            Case Is = ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter, ContentAlignment.TopCenter
            '                sfHeader.Alignment = StringAlignment.Center
            '            Case Is = ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
            '                sfHeader.Alignment = StringAlignment.Near
            '            Case Is = ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
            '                sfHeader.Alignment = StringAlignment.Far
            '            Case Else
            '                sfHeader.Alignment = StringAlignment.Near
            '        End Select
            '        e.Graphics.DrawString(item.Header, _
            '                              Me.iHeaderFont, _
            '                              New SolidBrush(Me.iHeaderForeColor), _
            '                              hRect, _
            '                              sfHeader)

            '        'Draw Description
            '        If item.Details <> "" Then
            '            Dim dRect As New Rectangle(e.Bounds.X, _
            '                                       e.Bounds.Y + hSize.Height, _
            '                                       e.Bounds.Width, _
            '                                       dSize.Height)
            '            Dim sfDetails As New StringFormat
            '            Select Case Me.iDetailsAlignment
            '                Case Is = ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter, ContentAlignment.TopCenter
            '                    sfDetails.Alignment = StringAlignment.Center
            '                Case Is = ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
            '                    sfDetails.Alignment = StringAlignment.Near
            '                Case Is = ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
            '                    sfDetails.Alignment = StringAlignment.Far
            '                Case Else
            '                    sfDetails.Alignment = StringAlignment.Near
            '            End Select
            '            e.Graphics.DrawString(item.Details, _
            '                                  Me.Font, _
            '                                  New SolidBrush(Me.iDetailsForeColor), _
            '                                  dRect, _
            '                                  sfDetails)
            '        End If

            '        'Draw Due date
            '        If item.DueDate <> DateTime.MinValue Then
            '            Dim cRect As New Rectangle(e.Bounds.X, _
            '                                       e.Bounds.Y + hSize.Height + dSize.Height + (lineSeperation * 2), _
            '                                       e.Bounds.Width, _
            '                                       cSize.Height)
            '            Dim sfDueDate As New StringFormat
            '            Select Case Me.iDueDateAlignment
            '                Case Is = ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter, ContentAlignment.TopCenter
            '                    sfDueDate.Alignment = StringAlignment.Center
            '                Case Is = ContentAlignment.BottomLeft, ContentAlignment.MiddleLeft, ContentAlignment.TopLeft
            '                    sfDueDate.Alignment = StringAlignment.Near
            '                Case Is = ContentAlignment.BottomRight, ContentAlignment.MiddleRight, ContentAlignment.TopRight
            '                    sfDueDate.Alignment = StringAlignment.Far
            '                Case Else
            '                    sfDueDate.Alignment = StringAlignment.Far
            '            End Select
            '            e.Graphics.DrawString(item.DueDate.ToString(Me.iDisplayDateFormat), _
            '                                  Me.iDueDateFont, _
            '                                  New SolidBrush(Me.iDueDateForeColor), _
            '                                  cRect, _
            '                                  sfDueDate)

            '        End If

            '        'Resume layout
            '        Me.ResumeLayout()

            '    End If
            'End If


    End Sub

    Protected Overrides Sub OnMeasureItem(e As System.Windows.Forms.MeasureItemEventArgs)
        MyBase.OnMeasureItem(e)

        If Me.Items.Count > 0 Then
            If e.Index <> -1 Then
                Dim gh As New GraphicsHelper
                e.ItemWidth = Me.Size.Width - 4
                If TypeOf Me.Items(e.Index) Is DetailListBoxItem Then
                    Dim item As DetailListBoxItem = Me.Items(e.Index)

                    If (item.Details <> "") _
                        AndAlso (item.Footer <> "") Then    'Header,Details, and Footer all available

                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim detailsSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Details, _
                                                                Me.iDetailsFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))
                        Dim FooterSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Footer, _
                                                                Me.iFooterFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))
                        If Me.iImagePositioning = ImagePositioningsEnum.Bottom Or Me.iImagePositioning = ImagePositioningsEnum.Top Then
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            detailsSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            FooterSize.Height + _
                                            Me.iGraphicsLineBreak + 32) + Me.iTextheigtCompensation
                        Else
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            detailsSize.Height) + Me.iTextheigtCompensation
                        End If
                    ElseIf (item.Details <> "") _
                        AndAlso (item.Footer = "") Then     'Header, Details available

                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim detailsSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Details, _
                                                                Me.iDetailsFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment))
                        If Me.iImagePositioning = ImagePositioningsEnum.Bottom Or Me.iImagePositioning = ImagePositioningsEnum.Top Then
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            detailsSize.Height + _
                                            Me.iGraphicsLineBreak + 32) + Me.iTextheigtCompensation
                        Else
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            detailsSize.Height) + Me.iTextheigtCompensation
                        End If
                    ElseIf (item.Details = "") _
                        AndAlso (item.Footer <> "") Then    'Header, footer available
                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                               item.Header, _
                                                               Me.iHeaderFont, _
                                                               e.ItemWidth, _
                                                               gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        Dim FooterSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Footer, _
                                                                Me.iFooterFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iFooterAlignment))
                        If Me.iImagePositioning = ImagePositioningsEnum.Bottom Or Me.iImagePositioning = ImagePositioningsEnum.Top Then
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + _
                                            FooterSize.Height + _
                                            Me.iGraphicsLineBreak + 32) + Me.iTextheigtCompensation
                        Else
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak) + Me.iTextheigtCompensation
                        End If
                    Else                                    'Only Header available
                        Dim headerSize As Size = gh.GetTextSize(Me.Handle, _
                                                                item.Header, _
                                                                Me.iHeaderFont, _
                                                                e.ItemWidth, _
                                                                gh.GetTextFormatObjectFromContentAlignment(Me.iHeaderAlignment))
                        If Me.iImagePositioning = ImagePositioningsEnum.Bottom Or Me.iImagePositioning = ImagePositioningsEnum.Top Then
                            e.ItemHeight = (headerSize.Height + _
                                            Me.iGraphicsLineBreak + 32) + Me.iTextheigtCompensation
                        Else
                            e.ItemHeight = (headerSize.Height) + Me.iTextheigtCompensation
                        End If
                    End If
                Else
                    'Normal draw
                    Dim item As Object = Me.Items(e.Index)
                    Dim sf As StringFormat = gh.GetTextFormatObjectFromContentAlignment(Me.iDetailsAlignment)
                    Dim tSize As Size = e.Graphics.MeasureString(item.ToString, _
                                                                  Me.iDetailsFont, _
                                                                  e.ItemWidth).ToSize
                    e.ItemWidth = e.ItemWidth
                    e.ItemHeight = tSize.Height
                End If
            End If
        End If

        'If Me.Items.Count > 0 Then
        '    Dim item As DetailListBoxItem = Me.Items(e.Index)
        '    Dim lineSeperation As Integer = 3
        '    Dim hSize As SizeF = e.Graphics.MeasureString(item.Header, Me.iHeaderFont, Me.Size.Width)
        '    Dim dSize As SizeF = Nothing
        '    Dim cSize As SizeF = Nothing
        '    If item.Details = "" Then
        '        dSize = New SizeF(0, 0)
        '    Else
        '        dSize = e.Graphics.MeasureString(item.Details, Me.Font, Me.Size.Width)
        '    End If
        '    If item.DueDate = DateTime.MinValue Then
        '        cSize = New SizeF(0, 0)
        '    Else
        '        cSize = e.Graphics.MeasureString(item.DueDate.ToString(Me.iDisplayDateFormat), Me.iDueDateFont, Me.Size.Width)
        '    End If
        '    e.ItemWidth = Me.Size.Width
        '    e.ItemHeight = hSize.Height + dSize.Height + cSize.Height + (lineSeperation * 3)
        '    If item.Details <> "" Then e.ItemHeight += lineSeperation
        '    If item.DueDate <> DateTime.MinValue Then e.ItemHeight += lineSeperation
        'End If

    End Sub

    Protected Overrides Sub OnSelectedIndexChanged(e As System.EventArgs)
        Me.Invalidate()
        MyBase.OnSelectedIndexChanged(e)
    End Sub

#End Region

End Class

Public Class DetailListBoxItem

    Public Header As String = "Header"
    Public Details As String = String.Empty
    Public Footer As String = String.Empty
    Public IconImage As Image = Nothing
    Public DataObject As Object = Nothing

    Public Sub New(Header As String, _
               Optional Details As String = "", _
               Optional Footer As Object = Nothing, _
               Optional IconImage As Image = Nothing, _
               Optional DataObject As Object = Nothing)
        Me.Header = Header
        Me.Details = Details
        Me.Footer = Footer
        Me.IconImage = IconImage
        Me.DataObject = DataObject
    End Sub

    Public Overrides Function ToString() As String
        Return Me.Header
    End Function

End Class



